#include "NodeVisitor.h"

using namespace std;

void FillVisitor::visit(PackageDeclarationNode *n) {
	n->SetIdentifier();

	n->containing_class = 0x0;
}
void FillVisitor::visit(ClassDeclarationNode *n){
	current_class = n;
	n->CollectModifiers();
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(FieldDeclarationNode *n){
	n->CollectModifiers();
	n->FillType();
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(MethodDeclarationNode *n){
	n->CollectModifiers();
	if (n->HasChildOfType(";") && (n->modifier & ModifiedNode::Native) == 0x0)
		n->modifier |= ModifiedNode::Abstract;
	n->FillType();
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;

	current_method = n;
}
void FillVisitor::visit(FormalParameterNode *n){
	n->FillType();
	((DeclarationNode*)n->parent)->identifier.append('$' + n->type_package_name + n->type_name + (n->type_meta.category & TypeMeta::Array ? "$" : ""));
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;

	current_method->number_of_parameters += 1;

}
void FillVisitor::visit(ConstructorDeclarationNode *n){
	n->CollectModifiers();
	n->SetIdentifier();
	n->identifier += '$';
	n->type_meta = TypeMeta(TypeMeta::Void, 0x0);
	n->containing_class = current_class;

	current_method = n;
}
void FillVisitor::visit(InterfaceDeclarationNode *n){
	current_class = n;
	n->CollectModifiers();
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(AbstractMethodDeclarationNode *n){
	n->CollectModifiers();
	n->modifier |= ModifiedNode::Abstract;
	n->FillType();
	n->SetIdentifier();
	n->DeleteLeafs();
	n->containing_class = current_class;

	current_method = n;
}
void FillVisitor::visit(LocalVariableDeclarationNode *n){

	n->FillType();
	n->SetIdentifier();
	
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(ClassInstanceCreationExpressionNode *n) {
	n->FillType();
	n->containing_class = current_class;
}
void FillVisitor::visit(ArrayCreationExpressionNode *n) {
	n->FillType();
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(CastExpressionNode *n) {
	n->FillType();
	n->DeleteLeafs();
	n->containing_class = current_class;
}
void FillVisitor::visit(ClassTypeNode *n) {
	n->FillType();
	n->containing_class = current_class;
}
void FillVisitor::visit(InterfaceTypeNode *n) {
	n->FillType();
	n->containing_class = current_class;
}
void FillVisitor::visit(ReferenceTypeNode *n) {
	n->FillType();
	n->containing_class = current_class;
}